package com.srcptit.java.training.kienbd.bt1;
import java.util.Scanner;
public class Muc2_Bai2_PTKN {
	static int a[]=new int[100];
	static int n;
	static void nhap()
	{
            Scanner sc=new Scanner(System.in);
            System.out.print("Nhap so phan tu : ");
            n=sc.nextInt();
            for(int i=1;i<=n;i++)
            {
		System.out.print("Phan tu thu "+i+" : ");
        	a[i]=sc.nextInt();
            }
            sc.close();
	}
	static void in()
	{
            System.out.print("Mang vua nhap : ");
            for(int i=1;i<=n;i++)
            System.out.print(a[i]+" ");
            System.out.println();
	}
        static void sx()
        {
            int hv;
            for(int i=1;i<n;i++)
            for(int j=i+1;j<=n;j++)
            if(a[i]>a[j])
            {
		hv=a[i];a[i]=a[j];a[j]=hv;
            }
       }
       static void dem_pt()
       {
            int b[]=new int[100];
            for(int i=1;i<=n;i++) b[i]=1;
            int i=1, dem;
            while(i<=n)
               {
                if(b[i]==1)
                {
                    dem=1;
                    int j=i+1;
                    while(a[j]==a[i])
                    {
			if( a[i]==a[j] ) { b[j]=0;dem++; }
			j++;
                    }
                    System.out.println("So "+a[i]+" xuat hien "+dem+" lan.");
                    i=j;
                }
               }	
        }
	public static void main(String args[])
        {
            nhap();
            in();
            sx();
            dem_pt();						
        }
}
